package com.sky.controller.user;


import com.sky.context.BaseContext;
import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShopCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user/shoppingCart")
@Api(tags = "用户端购物车接口")
@Slf4j
public class ShopCartController {

    @Autowired
    private ShopCartService shopCartService;


    @PostMapping("/add")
    @ApiOperation("添加购物车")
    public Result addShopCart (@RequestBody ShoppingCartDTO shoppingCartDTO){

        log.info("添加购物车");

        shopCartService.addShopCart(shoppingCartDTO);

        return Result.success();
    }


    @GetMapping("/list")
    @ApiOperation("查看购物车")
    public Result<List<ShoppingCart>> getShopCart(){

        log.info("查看购物车");

        List<ShoppingCart> list = shopCartService.getShopCart();

        return Result.success(list);
    }

    @DeleteMapping("/clean")
    @ApiOperation("清空购物车")
    public Result deleteShoppingCart (){

        Long userId = BaseContext.getCurrentId();

        shopCartService.deleteShoppingCart(userId);

        log.info("清空购物车");

        return Result.success();
    }


    @PostMapping("/sub")
    @ApiOperation("取消删减购物车菜品")
    public Result cancelShopingcatrDish(@RequestBody ShoppingCartDTO shoppingCartDTO){

        log.info("删减菜品或者套餐");

        shopCartService.sub(shoppingCartDTO);

        return Result.success();

    }



}
